-- RPC -- 
local function Skill1(inst, x, y, z)
    
    if inst:HasTag("playerghost")
    or inst.components.health:IsDead()
    or inst.components.i26skill == nil
    --or (inst.components.rider and inst.components.rider:IsRiding()) 
    then return end

    if inst.components.inventory ~= nil and not inst.components.inventory:IsOpenedBy(inst) then
        inst.components.inventory:Show()
        inst.components.inventory:Open()
    end

    if inst.components.i26skill.skillpoint > 0 then
        
        if inst.components.freezable ~= nil and inst.components.freezable:IsFrozen() then
            inst.components.freezable:Unfreeze()
        end
        if inst.components.pinnable ~= nil and inst.components.pinnable:IsStuck() then
            inst.components.pinnable:Unstick()
        end
        inst.components.rider:ActualDismount()
        inst.components.burnable:Extinguish()   --官方没有判断，那就不用判断，谁移除组件，科雷将终结他的游戏！
        if inst.components.inkable ~= nil and inst.components.inkable.inktime > 0 then
            inst.components.inkable.inktime = 0
        end
        if inst.components.inventory:IsHeavyLifting() then
            inst.components.inventory:DropItem(
                inst.components.inventory:Unequip(EQUIPSLOTS.BODY),
                true,
                true
            )
        end
        if inst.i26ggtask ~= nil then
            inst.i26ggtask:Cancel()
            inst.i26ggtask = nil
        end
        if inst.components.grogginess then
            inst.components.grogginess:ResetGrogginess()
            inst.components.grogginess:AddResistanceSource("i26", 6)
        end
        inst.i26ggtask = inst:DoTaskInTime(5, function()
            if inst.components.grogginess then
                inst.components.grogginess:ResetGrogginess()
                inst.components.grogginess:RemoveResistanceSource("i26")
            end
        end)
    end

    inst.components.i26skill:DoSkill(1, x, y, z)
end
local function Skill2(inst, x, y, z)
    if not inst.sg 
    or inst.sg:HasStateTag("busy")
    or inst.sg:HasStateTag("nointerrupt") 
    or inst.sg:HasStateTag("doing")
    or inst.components.health:IsDead()
    or inst.components.i26skill == nil
    or (inst.components.rider and inst.components.rider:IsRiding()) 
    then return end
    local weapon = inst.components.inventory and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
    if not weapon then return end 
    inst.components.i26skill:DoSkill(2, x, y, z)
end

AddModRPCHandler("i26_rpc", "Skill1", Skill1)
AddModRPCHandler("i26_rpc", "Skill2", Skill2)
